/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

/**
 *
 * @author Zhilin
 */
public class PasswordVerifier {
    private static final int SUCCESS = 0;
    private static final int LENGTH_PROBLEM = 1;
    private static final int NOT_CONTAIN_FULL = 2;
    
    private static int isPasswordSecure(String password){
        int numChar = password.length();
        if(numChar < 8 || numChar > 16) return LENGTH_PROBLEM;
        
        boolean upperFound = false;
        boolean lowerFound = false;
        boolean digitFound = false;
        for (char c : password.toCharArray()) {
            if (Character.isUpperCase(c)) {
                upperFound = true;
            }else if(Character.isLowerCase(c)){
                lowerFound = true;
            }else if(Character.isDigit(c)){
                digitFound = true;
            }
        }
        
        if(upperFound && lowerFound && digitFound) return SUCCESS;
        return NOT_CONTAIN_FULL;
    }
    
    public static String getPasswordErrorMsn(String password){
        switch(isPasswordSecure(password)){
            case LENGTH_PROBLEM:
                return "Password must have length between 8 - 10";
            case NOT_CONTAIN_FULL:
                return "Password must contain at least one uppercase, one lowercase and digit";
        }
        return null;
    }
}
